import React, { Component } from 'react';
import { Form, Input } from 'antd';
import PropTypes from 'prop-types';
import './modal.css';

class AddRoleForm extends Component {

  static propTypes = {
    setForm: PropTypes.func.isRequired,
  }

  formRef = React.createRef();  // form对象
  
  componentDidMount() {
    this.props.setForm(this.formRef);  // 调用父组件传递的函数，目的是将 参数以实参的形式传递给父组件
  }

  render() {
    const layout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 16 },
    };
    return (
      <div>
        <Form 
          {...layout} 
          ref={this.formRef}   
          name="control-ref" 
          onFinish={this.onFinish}
        >    
          <Form.Item 
            name="role_name" 
            label="角色名称" 
            rules={[{ required: true }]}
          >
            <Input placeholder="请输入角色名称"/>
          </Form.Item>
        </Form>
      </div>
      
    )
  }
}

export default AddRoleForm;